package lyq.spec.edu.practical;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


public class ThirdFragment extends Fragment {

    private WsReceiver receiver=null;
    private TextView mTextView;
    private ImageView mImageView;
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View intelligent_humiture = inflater.inflate(R.layout.fragment_third, container, false);

        Intent intent = new Intent(getActivity(),MyService.class);
        getActivity().startService(intent);
        mTextView = intelligent_humiture.findViewById(R.id.intelligent_humiture);
        mImageView = intelligent_humiture.findViewById(R.id.play);

        //注册广播接收器
        receiver=new WsReceiver();
        IntentFilter filter=new IntentFilter();
        filter.addAction("lyq.spec.edu.MyService");
        getContext().registerReceiver(receiver,filter);
        /*return inflater.inflate(R.layout.fragment_third, container, false);*/
        return intelligent_humiture;
    }
    /**
     * 获取广播数据
     *
     * @author jiqinlin
     *
     */
    public class WsReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle=intent.getExtras();
            String ws=bundle.getString("count");
            mTextView.setText(ws);
        }

    }



}
